<%@ page language="java" contentType="text/html; charset=UTF-8"  pageEncoding="UTF-8"%>

<table id="weixinTypeDate"></table> 
<div id="weixinTinsongGrid_bar" style="padding:5px;height:auto">
	<a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-remove',plain:true" onclick="pushArticles()">推送选中</a>
	<a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-edit',plain:true" onclick="updateArticles()">修改</a>
</div>
<script type="text/javascript">
var weixinTypeDate=undefined;
weixinTypeDate=$('#weixinTypeDate').datagrid({
	url:'tuisong/findTypesByPage.do',
	striped:true,
	fit:true,
	striped : true,
	collapsible : true,//显示可折叠按钮
	fitColumns:true,
	loadMsg:"正在加载中...",
	pagination:true,
	pageNumber:1,
	pageSize:10,
	pageList:[10,20,30,40,50],
	remoteSort:false,
	toolbar:"#weixinTinsongGrid_bar",
	/* onClickCell: onClickSjtsCell, */
	columns:[[
	  		{field:'id',sortable:true,align:'center',checkbox:true},
	  		{field:'title',title:'文章标题',width:80,align:'center',editor:'text'},
	  		{field:'content',title:'内容',width:150,align:'center',editor:'text'},
	  		{field:'picUrl',title:'图片',width:80,align:'center',
	  			formatter: function(value,row,index){
						return "<img width='60px' height='60px' src='"+row.picUrl+"'>";
				} 
},
	  		{field:'url',title:'跳转链接',width:150,align:'center',editor:'text'},
	  		{field:'uname',title:'上次修改者',width:60,align:'center'},
	  		{field:'updateTime',title:'修改日期',width:80,align:'center'},
	  		{field:'status',title:'是否推送过',width:80,align:'center',
	  			editor:{type:'checkbox',options:{on:'是',off:'否'}}},
	  		{field:'echoStatus',title:'设为关注时推送',width:80,align:'center',
	  			editor:{type:'checkbox',options:{on:'是',off:'否'}}}
	  		]]
	
});
function pushArticles(){
	var rows = $('#weixinTypeDate').datagrid('getSelections');
	if(rows.length==0){
		$.messager.alert('温馨提示','请选择要推送的行!','info');
		return;
	}
	if(rows.length>8){
		$.messager.alert('温馨提示','一次最多推送八条数据!','info');
		return;
	}
	var ids="";
	for(var i=0;i<rows.length-1;i++){
		ids+=rows[i].id+",";
	}
	ids+=rows[rows.length-1].id;
	$.get("msgPush/msgPush.do",{ids:ids},function(data){
		if(data){
			$.messager.show({
				title:'成功提示',
				msg:'图文消息推送成功.',
				timeout:5000,
				showType:'slide'
			});
		}
	},"json");
	
}
/* 
$.extend($.fn.datagrid.methods, {
	editCell: function(jq,param){
		return jq.each(function(){
			var opts = $(this).datagrid('options');
			var fields = $(this).datagrid('getColumnFields',true).concat($(this).datagrid('getColumnFields'));
			for(var i=0; i<fields.length; i++){
				var col = $(this).datagrid('getColumnOption', fields[i]);
				col.editor1 = col.editor;
				if (fields[i] != param.field){
					col.editor = null;
				}
			}
			$(this).datagrid('beginEdit', param.index);
			for(var i=0; i<fields.length; i++){
				var col = $(this).datagrid('getColumnOption', fields[i]);
				col.editor = col.editor1;
			}
		});
	}
});

var editIndex = undefined;
function endEditing(){
	if (editIndex == undefined){return true}
	if ($('#weixinTypeDate').datagrid('validateRow', editIndex)){
		$('#weixinTypeDate').datagrid('endEdit', editIndex);
		editIndex = undefined;
		return true;
	} else {
		return false;
	}
}
function onClickSjtsCell(index, field){
	if (endEditing()){
		$('#weixinTypeDate').datagrid('selectRow', index)
				.datagrid('editCell', {index:index,field:field});
		editIndex = index;
	}
} */
</script>